const dao = require('./base');

module.exports = {

    bancorPricesList: function (condition, fields = "*", by = []) {
        let sql = `SELECT ${fields} from ex_bancor_prices a where 1=1`;
        let pre = [];
        if (condition.id !== undefined && condition.id !== '') {
            sql += ` and a.id = ?`;
            pre.push(condition.id);
        }
        if (condition.contract !== undefined && condition.contract !== '') {
            sql += ` and a.contract = ?`;
            pre.push(condition.contract);
        }
        sql = dao.by(sql, by);
        let limit = dao.limit(sql, condition, pre);
        sql = limit.sql;
        pre = limit.pre;
        return dao.query(sql, pre).then((results, fields) => {
            return results;
        }).catch((err) => {
            throw new Error(err + " sql：" + sql + " pre：" + pre);
        });
    },

    bancorPricesAdd: function (fields = {}) {
        let sql = "INSERT INTO `ex_bancor_prices` (`contract`, `price`) VALUES " +
            "(?,?)";
        let pre = [];
        pre.push(fields.contract);
        pre.push(fields.price);
        return dao.query(sql, pre).then((results, fields) => {
            return results;
        }).catch((err) => {
            throw new Error(err + " sql：" + sql + " pre：" + pre);
        });
    },


};
